package com.ws.controller;

import com.ws.common.PaasPage;
import com.ws.common.PaasResponse;
import com.ws.entity.Feedback;
import com.ws.response.FeedbackPageResponse;
import com.ws.response.FeedbackResponse;
import com.ws.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author ：ws
 * @date ：Created in 2023/10/24 10:45
 * @description：TODO
 * @modified By：
 * @version: 1.0.0
 */
@Controller
@RefreshScope
@CrossOrigin
@RequestMapping("/feedBack")
public class FeedBackController {
    @Autowired
    FeedbackService feedbackService;

    /**
     * 反馈意见查询接口
     * @param pageable
     * @return
     */
    @GetMapping("")
    public ResponseEntity<FeedbackPageResponse> getFeedbackPage(
            @PageableDefault(page = 1, direction = Sort.Direction.DESC) Pageable pageable,
            @RequestParam(value="readerId",required=false) Long readerId,
            @RequestParam(value="statusCd",required=false) String statusCd
    ){
        PaasPage<Feedback> feedbackPaasPage = feedbackService.getFeedbackPage(pageable,readerId,statusCd);
        return ResponseEntity.ok(new FeedbackPageResponse(feedbackPaasPage));
    }

    /**
     * 反馈意见新增接口
     * @param feedback
     * @return
     */
    @PostMapping("")
    public ResponseEntity<FeedbackResponse> saveFeedback(@RequestBody @Valid Feedback feedback){
        Feedback feedback1 = feedbackService.saveFeedback(feedback);
        return ResponseEntity.ok(new FeedbackResponse(feedback1));
    }

    /**
     * 查询对应反馈意见的基本信息
     * @param feedbackId
     * @return
     */
    @GetMapping("/{feedbackId}/basicInfo")
    public ResponseEntity<FeedbackResponse> getFeedbackBasicInfo(@PathVariable Long feedbackId){
        Feedback feedback = feedbackService.getFeedbackBasicInfo(feedbackId);
        return ResponseEntity.ok(new FeedbackResponse(feedback));
    }

    /**
     * 删除对应的反馈意见
     * @param feedbackId
     * @return
     */
    @PostMapping("/d/{feedbackId}")
    public ResponseEntity delFeedback(@PathVariable Long feedbackId)  {
        feedbackService.delFeedback(feedbackId);
        return ResponseEntity.ok(new PaasResponse());
    }

    /**
     * 修改对应的反馈意见
     * @param feedbackId
     * @return
     */
    @PostMapping("/u/{feedbackId}")
    public ResponseEntity<FeedbackResponse> updateFeedback(@PathVariable Long feedbackId,@RequestBody Feedback feedback)  {
        Feedback feedback1 = feedbackService.updateFeedback(feedbackId,feedback);
        return ResponseEntity.ok(new FeedbackResponse(feedback1));
    }
}
